{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 7.26 Pipe Partially Filled with Flowing Water"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Given a cast iron pipe is 2/3 filled with a steady, uniform flow of water at 60 deg F. \n",
    "The pipe has an inside diameter of 24\" and a slope of .75\"/foot\n",
    "\n",
    "Find the flow rate in gallons/minute."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:19:25.601395Z",
     "iopub.status.busy": "2022-08-22T01:19:25.600676Z",
     "iopub.status.idle": "2022-08-22T01:19:26.289020Z",
     "shell.execute_reply": "2022-08-22T01:19:26.288222Z"
    }
   },
   "outputs": [],
   "source": [
    "from fluids.units import *\n",
    "from math import pi\n",
    "Di = 24*u.inch\n",
    "depth = 2/3*Di\n",
    "S = 0.75*u.inch/u.ft\n",
    "rho = 62.364*u.lb/u.ft**3\n",
    "mu = 1.1*u.cP\n",
    "eD = 0.00036 # roughness not given in problem, only relative roughness"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:19:26.294894Z",
     "iopub.status.busy": "2022-08-22T01:19:26.294183Z",
     "iopub.status.idle": "2022-08-22T01:19:26.311411Z",
     "shell.execute_reply": "2022-08-22T01:19:26.310633Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.20670024467339204 <Unit('meter ** 2')>,\n",
       " 1.1647220208174018 <Unit('meter')>,\n",
       " 0.1774674480081778 <Unit('meter')>,\n",
       " 0.7098697920327112 <Unit('meter')>)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Use the TANK class to make the geometry easier\n",
    "tank = TANK(D=Di, L=1e-100*u.m, horizontal=True)\n",
    "A = tank.SA_from_h(depth)/2 # wetted surface area of a paper thin tank - divide by two as there is only one side\n",
    "\n",
    "tank = TANK(D=Di, L=1e100*u.m, horizontal=True)\n",
    "P = tank.SA_from_h(depth)/tank.L\n",
    "\n",
    "Rh = A/P\n",
    "Dh = 4*Rh\n",
    "A, P, Rh, Dh"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false,
    "execution": {
     "iopub.execute_input": "2022-08-22T01:19:26.334062Z",
     "iopub.status.busy": "2022-08-22T01:19:26.333126Z",
     "iopub.status.idle": "2022-08-22T01:19:26.351280Z",
     "shell.execute_reply": "2022-08-22T01:19:26.350468Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "24410.948055443227 gallon/minute"
      ],
      "text/latex": [
       "$24410.948055443227\\ \\frac{\\mathrm{gallon}}{\\mathrm{minute}}$"
      ],
      "text/plain": [
       "24410.948055443227 <Unit('gallon / minute')>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 10 meter length basis assumed\n",
    "L = 10.0*u.m\n",
    "dH = L*S\n",
    "dP = dH*rho*u.gravity\n",
    "\n",
    "fd = .0155 # initial guess\n",
    "for i in range(5):\n",
    "    K = K_from_f(fd=fd, L=L, D=Dh)\n",
    "    v = (2*dP/(K*rho))**0.5\n",
    "    Q = A*v\n",
    "    # update friction factor\n",
    "    Re = Reynolds(D=Dh, rho=rho, mu=mu, V=v)\n",
    "    fd = friction_factor(Re=Re, eD=eD)\n",
    "Q.to(u.gal/u.min)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The solution given in Crane is 24500 gpm without iteration."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
